/*
 * stack.c
 *
 *  Created on: 25.12.2012
 *      Author: Michael
 */
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"

Stack_t* createStack(void) {
	Stack_t* pCreate = malloc(sizeof(Stack_t*));
	pCreate->_index = -1;
	pCreate->_size = 100;
	pCreate->push = push;
	pCreate->pop = pop;
	pCreate->peak = peak;
	pCreate->print = print;
	return pCreate;
}

void push(Stack_t* pThis, int value) {
	pThis->_index++;
	pThis->_values[pThis->_index] = value;
}

int pop(Stack_t* pThis) {
	int value = pThis->_values[pThis->_index];
	pThis->_index--;
	if (pThis->_index < 0) {
		pThis->_index = -1;
	}
	return value;
}

int peak(Stack_t* pThis) {
	return pThis->_values[pThis->_index];
}

void print(Stack_t* pThis) {
	unsigned int i;

	if (pThis->_index != -1) {
		for (i = 0; i <= pThis->_index; ++i) {
			printf("%d\n", pThis->_values[i]);
		}
		printf("\n");
	}
}
